package day05;
import sun.security.rsa.RSACore;

import java.util.Scanner;
import java.util.Arrays;
public class Exercise02 {
    public static void main(String[] args) {
        /*//1. Addition随机加法运算器
        Scanner sc = new Scanner(System.in);
        int score = 0;
        for (int i = 1; i <=10; i++) {
            int a= (int)(Math.random()*10);
            int b= (int)(Math.random()*10);
            int result = a*b;
            System.out.println("("+i+")"+a+"*"+b+"=?");
            int answer = sc.nextInt();
            if (answer==result) {
                System.out.println("恭喜你答对了！");
                score+=10;
            } else {
                System.out.println("答错了");
            }
        }
        System.out.println("最终的成绩为:"+score);

         */


        /*//2. MultiTable九九乘法表
        for (int num = 1; num <= 9; num++) {
            for (int j = 1; j <=num ; j++) {
                System.out.print(j+"*"+num+"="+j*num+"\t");
            }
            System.out.println();
        }

         */


        /*//3. 数组小代码练习：声明、初始化、访问、遍历
        int[] a = new int[6];
        double[] b = new double[7];
        boolean[] c =  new boolean[8];

        int[] arr1 = new int[3];
        int[] arr2 = {1,2,3};
        int[] arr3 = new int[]{1,2,3,4,5};
        int[] arr4;
        arr4 = new int[]{2,3,4,5};

        int[] arr = new int[5];
        System.out.println(arr.length);//输出数组的长度
        arr[0] = 2;
        arr[1] = 4;
        arr[2] = 6;
        arr[3] = 8;
        arr[4] = 10;
        System.out.println(arr[arr.length-1]);//输出数组最后一个元素值
        //System.out.println(arr[arr.length]);//数组操作异常，下标越界

        int [] arr5 = new int[10];//遍历数组
        for (int i = 0; i <arr5.length ; i++) {
            arr5[i]= (int)(Math.random()*100);
            System.out.println(arr5[i]);
        }

         */


       /*//4. MaxOfArray求数组元素最大值
        int[] arr = new int[20];
        for (int i = 0; i < arr.length ; i++) {
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        int max = arr[0];
        for (int i = 1; i <arr.length ; i++) {
            if (max<arr[i]){
                max = arr[i];
            }
        }
        System.out.println("最大值为:"+max);

        */


        //5. 对数组进行升序排列，并输出排序后的结果
        int[] arr = new int[15];
        for (int i = 0; i < arr.length ; i++) {
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        Arrays.sort(arr);
        System.out.println("从小到大排序为:");
        for (int i = 0; i < arr.length; i++) {//从小到大
            System.out.println(arr[i]);
        }
        System.out.println("从大到小排序为:");
        for (int i = arr.length-1; i >= 0; i--) {//从大到小
            System.out.println(arr[i]);
        }
    }
}
